<?php
error_reporting(E_ALL);

/**
 * untitledModel - class.Editeur.php
 *
 * $Id$
 *
 * This file is part of untitledModel.
 *
 * Automatically generated on 26.02.2009, 15:28:43 with ArgoUML PHP module 
 * (last revised $Date: 2008-04-19 08:22:08 +0200 (Sat, 19 Apr 2008) $)
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/**
 * Short description of class Editeur
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class Journal
{

    /**
     * Short description of attribute IDEditeur
     *
     * @access public
     * @var Integer
     */
    private $IDJournal = null;

    /**
     * Short description of attribute Nom
     *
     * @access public
     * @var String
     */
    private $Nom = null;

    /**
     * Short description of attribute URL
     *
     * @access public
     * @var String
     */
    private $URL = null;

    /**
     * Short description of attribute URLLogo
     *
     * @access public
     * @var String
     */
    private $URLLogo = null;
    
    /**
     * Short description of attribute prixEdition
     *
     * @access public
     * @var Integer
     */
    private $prixEdition = null;
    
    private $IDmaisonEdition = null;
    
    private $IDediteur = null;

    // --- OPERATIONS ---

    public function getIDJournal(){
    	return $this->IDJournal;
    }
    
    public function setIDJournal($IDJournal){
    	$this->IDJournal = $IDJournal;
    }

    public function getNom(){
    	return $this->Nom;
    }
    
    public function setNom($Nom){
    	$this->Nom = $Nom;
    }
    
    public function getPrixEdition(){
    	return $this->prixEdition;
    }
    
    public function setPrixEdition($prixEdition){
    	$this->prixEdition = $prixEdition;
    } 

    public function getURL(){
    	return $this->URL;
    }
    
    public function setURL($Url){
    	$this->URL = $Url;
    }
    
    public function getURLLogo(){
    	return $this->URLLogo;
    }
    
	public function setURLLogo($UrlLogo){
    	$this->URLLogo = $UrlLogo;
    }
    
    public function getIDMaisonEdition(){
    	return $this->IDmaisonEdition;
    }
    
    public function setIDMaisonEdition($IDmaisonEdition){
    	$this->IDmaisonEdition = $IDmaisonEdition;
    }
    
    public function getIDEditeur(){
    	return $this->IDediteur;
    }
    
    public function setIDEditeur($Editeur){
    	$this->IDediteur = $Editeur;
    }
    
	public static function recupAllValid(){
		
		$i = 0;
		$result = Array();
		
		// Récupération de la connexion et préparation de la requête.
		$tbh = ConnexionBD::getInstance();
		/*$tbh->query("INSERT INTO compte_client VALUES ('','$this->Nom','$this->Prenom',
			'$this->AdresseMail', '$this->DateNaissance', '$this->Password', 0, 0)");*/
		$stat = $tbh->prepare("SELECT DISTINCT journal.* FROM (journal CROSS JOIN edition) WHERE journal.id_journal=edition.id_journal AND edition.date_edition > SUBDATE(CURDATE(), INTERVAL :day DAY)");
		$array = array(':day' => 7);
		$stat->execute($array);
		$arrValues = $stat->fetchAll(PDO::FETCH_ASSOC);
		foreach ($arrValues as $row){
			$journal = new Journal();
			$journal->setNom($row['nom']);
			$journal->setIDJournal($row['id_journal']);
			$journal->setPrixEdition($row['prix_journal']);
			$journal->setURL($row['URL']);
			$journal->setURLLogo($row['URLLogo']);
			$journal->setIDMaisonEdition($row['id_maison_edition']);
			$journal->setIDEditeur($row['id_editeur']);
			
			$result[$i]=$journal;
			$i++;
		}
		
		return $result;
	}
	
	public function recup($IdJournal){
		
		// Récupération de la connexion et préparation de la requête.
		$tbh = ConnexionBD::getInstance();
		$stat = $tbh->prepare("SELECT * FROM journal WHERE id_journal = :id_journal");
		$array = array(':id_journal' => $IdJournal);
		$stat->execute($array);
		
		$arrValues = $stat->fetchAll(PDO::FETCH_ASSOC);
		foreach ($arrValues as $row){
			$this->setNom($row['nom']);
			$this->setIDJournal($row['id_journal']);
			$this->setPrixEdition($row['prix_journal']);
			$this->setURL($row['URL']);
			$this->setURLLogo($row['URLLogo']);
			$this->setIDMaisonEdition($row['id_maison_edition']);
			$this->setIDEditeur($row['id_editeur']);
		}
	}
	
	public function add(){
		
		// Récupération de la connexion et préparation de la requête.
		$tbh = ConnexionBD::getInstance();
		$stat = $tbh->prepare("INSERT INTO journal SET nom=:nom,
			URL=:URL, prix_journal =:prix, id_maison_edition=:maisonEdition,
			URLLogo=:URLLogo,id_editeur=:editeur");
		$array = array(':nom'		=> $this->getNom(),
						':URL'		=> $this->getURL(),
						':prix'		=> $this->getPrixEdition(),
						':maisonEdition'		=> $this->getIDMaisonEdition(),
						':URLLogo'	=> $this->getURLLogo(),
						':editeur'	=> $this->getIDEditeur()
		);
		$stat->execute($array);
	}
	
	public static function getJournauxEditeur($editeurId){
		$tbh = ConnexionBD::getInstance();
		$stat = $tbh->prepare("SELECT * FROM journal WHERE id_editeur = :id");
		$array = array(':id' => $editeurId);
		$stat->execute($array);
		
		$journaux = array();
		$arrValues = $stat->fetchAll(PDO::FETCH_ASSOC);
		foreach ($arrValues as $row){
			$journal = new Journal();
			$journal->setNom($row['nom']);
			$journal->setIDJournal($row['id_journal']);
			$journal->setPrixEdition($row['prix_journal']);
			$journal->setURL($row['URL']);
			$journal->setURLLogo($row['URLLogo']);
			$journal->setIDMaisonEdition($row['id_maison_edition']);
			$journal->setIDEditeur($row['id_editeur']);
			$journaux[] = $journal;
		}
		
		return $journaux;
	}

} /* end of class Editeur */

?>